#include<iostream>
using namespace std;	
const int N = 25;
int arr[N];
int st[N];
int parent[N];
int n;
int k;
bool flag;
bool prime(int x)
{
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) {
			return 0;
		}
	}
	return 1;
}
void dfs(int u,int last)
{
	if (u > n) {
		if (prime(parent[n] + 1)) {
			if (!flag) {
				cout << "Case " << k << ":" << endl; 
				flag = 1;
			}
			for (int i = 1; i <= n - 1; i++) {
				cout << parent[i] << " ";
			}
			cout << parent[n] << endl;
		}
		return;
	}
	for (int i = 1; i <= n; i++) {
		if (!st[i] && prime(i + last)) {
			st[i] = 1;
			parent[u] = i;
			dfs(u + 1, i);
			st[i] = 0;
			parent[u] = 0;
		}
	}
}
int main()
{
	while (cin >> n) {
		k++;
		memset(st, 0, sizeof(st));
		memset(parent, 0, sizeof(parent));
		flag = 0;
		st[1] = 1;
		parent[1] = 1;
		dfs(2, 1);
		cout << endl;
	}
	return 0;
}